package com.zy.bootdemo.service.impl;

import com.zy.bootdemo.entity.CustomerEntity;
import com.zy.bootdemo.mapper.CustomerMapper;
import com.zy.bootdemo.mapper.RoomMapper;
import com.zy.bootdemo.service.CustomerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CustomerServicelmpl implements CustomerService {
    @Resource
    CustomerMapper customerMapper;
    @Resource
    RoomMapper roomMapper;
    @Override
    public List<CustomerEntity> selectAll(){
        return  customerMapper.selectAll();
    }

    @Override
    public boolean insertOne(String cName, String cNum, String cPhone, Integer rNum) {
        if(cName == null || cName == ""
                || cNum == null || cNum == ""
                || cPhone == null || cPhone == ""
                || rNum == null || rNum == 0) return false;

        return  customerMapper.insertOne(cName,cNum,cPhone,rNum) != 0 &&  roomMapper.stay(rNum, 1) != 0;

    }

    @Override
    public CustomerEntity selectOne(Integer id) {
        return customerMapper.selectOne(id);
    }

    @Override
    public boolean delOne(Integer id) {
        if(id == null || id == 0) return  false;
        CustomerEntity customerEntity= selectOne(id);
        return customerMapper.delOne(id) != 0 && roomMapper.stay(customerEntity.getRoomEntity().getRId(),0)!=0;
    }

}
